package org.example.dao;

import org.example.controller.pojo.User;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class UserRepository {
    private static Map<Integer, User> users = new HashMap<Integer, User>();

    static {
        for (int i = 1; i <= 3; i++) {
            User user = new User(i, "name " + i);
            users.put(i, user);
        }
    }

    public User getById(Integer id) {
        return users.get(id);
    }

    public void updateUser(User user) {
        Integer userId = user.getId();
        User tUser = users.get(userId);
        tUser.setName(user.getName());
        users.put(userId, tUser);
    }
}
